<?php
/**
 *	@author wyl
 *	@date 2015-10-23 13:38:11
 */
class AutoBidFilter{
	public function __construct(){
		
	}	
	
	private function normalize($result){
		$resultData=array();
		foreach($result as $auction){
			$resultData[$auction['auction_id']][]=$auction['customer_id'];
		}
		return $resultData;		
	}
	
	public function getAutoBidList($auctionID=NULL){
		$sql='
				SELECT
					a.auction_id,a.customer_id,a.amount
				FROM
					auction_pool AS p
				LEFT JOIN autobid AS a ON p.auction_id = a.auction_id
				WHERE
					1
				AND p.end_time <=1440858667+5
				AND p.winner_id <> a.customer_id
				AND a.amount > 0
				AND p.`status` = 1	
			';
		$sql=!$auctionID?$sql:$sql.' AND a.auction_id='.$auctionID;
		$sql.=' ORDER BY a.sort ASC';
		$result=Yii::app()->db->createCommand($sql)->queryAll();
		if (!empty($result)) {
			return $this->normalize($result);
		}
		return FALSE;
	}
}